using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP.Classes;

namespace ERP.View
{
    public partial class viewUsers : DevExpress.XtraEditors.XtraForm
    {
        public viewUsers()
        {
            InitializeComponent();
        }
        public cs_hmr_nhanvienInfo nv = new cs_hmr_nhanvienInfo();
        public cs_hmr_usersInfo user = new cs_hmr_usersInfo();
        public int flag = 0;

        private void viewUsers_Load(object sender, EventArgs e)
        {
            this.Load_Data();
            this.Load_Info();
            this.CheckUser();
        }
        private void CheckUser()
        {
            cs_hmr_userrightInfo userright = new cs_hmr_userrightInfo();
            userright.groupid = this.user.groupid;
            cs_hmr_winformInfo wf = new cs_hmr_winformInfo();
            wf.tenform = this.Name;
            if (wf.Get_Info() > 0)
            {
                userright.form_id = wf.formid;
                userright.Get_Info();
                if (userright.savedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.deletedata == 0)
                {
                }
                if (userright.updatedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.printreport == 0)
                {
                }
            }
        }

        private void Load_Data()
        {
            cs_hmr_nhom_nguoi_dungInfo nhom = new cs_hmr_nhom_nguoi_dungInfo();
            DataSet ds = new DataSet("ds");
            ds = nhom.Get_List();
            this.cboNhom.Properties.DataSource = ds.Tables[0];
            cs_hmr_donviInfo dv = new cs_hmr_donviInfo();
            ds = new DataSet("ds");
            ds = dv.Get_List_1();
            this.cboDonvi.Properties.DataSource = ds.Tables[0];
        }

        private void Load_Info()
        {
            this.user.id_nv = this.nv.manhanvien;
            this.user.username = this.nv.nhanvien_id;
            if (this.user.Get_Info() > 0)
            {
                this.flag = 2;
            }
            else
            {
                this.flag = 1;
            }
            this.txtTaikhoan.Text = this.nv.nhanvien_id;
            this.txtHoten.Text = this.nv.hoten;
            this.txtMatkhau.Text = this.user.pass;
            this.cboNhom.EditValue = this.user.groupid;
            this.cboDonvi.EditValue = this.user.donvi_thaotac;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose(true);
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            this.user.pass = this.txtMatkhau.Text.Trim();
            this.user.groupid = int.Parse(this.cboNhom.EditValue.ToString().Trim());
            this.user.donvi_thaotac = this.cboDonvi.EditValue.ToString().Trim();
            this.user.ExcuteProcedure(this.flag);
            this.Dispose(true);
        }
    }
}